import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:state_management_provider/Screens/BasketPage.dart';
import 'package:state_management_provider/provider/FruitsProvider.dart';

class FruitsListPage extends StatelessWidget {
  const FruitsListPage({Key key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    final fruitProvider = Provider.of<FruitProvider>(context);
    return Scaffold(
      appBar: AppBar(
        title: Text('IIT Madras Fruit Shop'),
        actions: [
          IconButton(icon: Icon(Icons.shopping_cart), onPressed: (){
            Navigator.push(context,MaterialPageRoute(builder: (_)=> BasketPage()));
          })
        ],
      ),
      body: ListView(
        children: fruitProvider.fruits.map((e) {
          return ListTile(
            title: Text('${e.fName}'),
            subtitle: Text('${e.fDesc}'),
            trailing: IconButton(
                icon: e.addToCart == false
                    ? Icon(Icons.shopping_bag,color: Colors.black,)
                    : Icon(Icons.delete,color: Colors.red),
                onPressed: () {
                  fruitProvider.cartOperation(e);
                }),
          );
        }).toList(),
      ),
    );
  }
}
